﻿package com.wandian.view.components.ui.chip
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
  
	/**   
	 * 加注金额动画
	 * @author long
	 * @QQ 108232706
	 * @version 1.0   
	 */ 
    public class AddChip extends Sprite
    {
        public var countChip:CountChip;
        private var _bg:Sprite;
        private var _txt:TextField;
        private var _nRecordNum:int;
        private var _mcChip:Sprite;

        public function AddChip(mcChip:Sprite) : void
        {
            this._bg = new Sprite();
            this._txt = new TextField();
            this._mcChip = mcChip;
            this.countChip = new CountChip();
            this._mcChip.addChild(this.countChip);
            this._txt.autoSize = TextFieldAutoSize.LEFT;
            this._txt.selectable = false;
            this._bg.graphics.clear();
            this._mcChip.addChild(this._bg);
            this._mcChip.addChild(this._txt);
            return;
        }

        public function showChip(param1:int) : void
        {
            this.countChip.recursionHandler(param1);
            return;
        }

        /**
         * 隐藏Chip
         */
        public function removeChip() : void
        {
            this.countChip.removeChip();
            this.hideTxtBg();
            return;
        }

        public function get nChip() : int
        {
            return this._nRecordNum;
        }

        public function hideTxtBg() : void
        {
            this._nRecordNum = 0;
            this._txt.text = "";
            this._bg.graphics.clear();
            return;
        }

        public function showTxtBg(param1:int, param2:Boolean = false) : void
        {
            var _loc_4:uint = 0;
            var _loc_5:Number = NaN;
            if (param1 == 0)
            {
                return;
            }
            this._nRecordNum = param1;
            this._txt.text = "" + param1.toString();
            var _loc_3:* = (param1.toString().length + 2) * 12 / 2;
            this._txt.width = _loc_3;
            this._txt.x = -(_loc_3 / 2 - this.countChip.width / 2) + 2;
            this._txt.y = 14;
            _loc_4 = 0;
            _loc_5 = 1;
            if (param2)
            {
                this._txt.textColor = 16776960;
            }
            else
            {
                this._txt.textColor = 1046799;
            }
            this._bg.graphics.clear();
            this._bg.graphics.beginFill(_loc_4, _loc_5);
            this._bg.graphics.drawRoundRect(0, 0, _loc_3, 12, 10, 10);
            this._bg.graphics.endFill();
            this._bg.x = this._txt.x - 4;
            this._bg.y = this._txt.y + 4;
            if (!this._mcChip.contains(this._bg))
            {
                this._mcChip.addChild(this._bg);
            }
            if (!this._mcChip.contains(this._txt))
            {
                this._mcChip.addChild(this._txt);
            }
            return;
        }

    }
}
